from django.db import models

# Create your models here.
# import settings

class MemoryUser(models.Model):
    user_id = models.CharField(verbose_name="用户id", max_length=100, db_index=True)
    username = models.CharField(verbose_name="用户昵称", max_length=50, null=False)
    password = models.CharField(verbose_name="用户密码", max_length=50, null=False)
    motto = models.CharField(verbose_name="个性签名", max_length=100, null=True, blank=True)
    pic = models.CharField(verbose_name="头像", max_length=150, null=True, blank=True)
    email = models.CharField(verbose_name="邮箱", max_length=30, null=True, blank=True)
    create_time = models.DateTimeField(verbose_name="创建时间", auto_now_add=True)
    update_time = models.DateTimeField(verbose_name="最后修改时间", auto_now=True)

    class Meta:
        verbose_name = "用户信息表"
        verbose_name_plural = verbose_name
        ordering = ["-create_time"]
        db_table = "memory_storage_memoryuser"


class Memory(models.Model):

    MEMORY_IMPORTANCE_LIST = [(1, "平平淡淡"), (2, "较为触动"), (3, "非常重要"), (4, "不愿忘记")]

    # 暂设置外键为空
    belonging_user = models.ForeignKey(MemoryUser, models.CASCADE, null=True)

    memory_title = models.CharField(verbose_name="记忆标题", max_length=30)
    memory_content = models.TextField(verbose_name="记忆内容")
    attachment_name = models.CharField(verbose_name="附件名称", max_length=32, null=True, blank=True)
    attachment_url = models.TextField(verbose_name="附件URL", null=True, blank=True)
    memory_level = models.IntegerField(verbose_name="重要级别", choices=MEMORY_IMPORTANCE_LIST, default=1)
    is_modify = models.SmallIntegerField(verbose_name="可修改状态", choices=[(1, '打开'), (0, '关闭')], default=1)
    is_display = models.SmallIntegerField(verbose_name="是否可展示", choices=[(1, '打开'), (0, '关闭')], default=1)
    status = models.SmallIntegerField(verbose_name="锁存状态", choices=[(1, '打开'), (0, '关闭')], default=1)
    end_time = models.DateTimeField(verbose_name="锁存结束时间")
    create_time = models.DateTimeField(verbose_name="创建时间", auto_now_add=True)
    update_time = models.DateTimeField(verbose_name="最后修改时间", auto_now=True)


    class Meta:
        verbose_name = "记忆信息表"
        verbose_name_plural = verbose_name
        ordering = ["-create_time"]
        db_table = "memory_storage_memory"


class Reply(models.Model):
    memory = models.ForeignKey(Memory, models.CASCADE)
    author = models.CharField(max_length=100)
    type = models.CharField(max_length=20, choices=[("0", "like"), ("1", "dislike"), ("2", "collect")])
    # text = models.CharField(max_length=280, null=True, blank=True)
    # at_person = models.CharField(max_length=50, null=True, blank=True)

    def __str__(self):
        return "{} on {}".format(self.author, self.memory.memory_title)